package org.jeecg.modules.demo.stockmanage.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.demo.stockmanage.entity.*;
import org.jeecg.modules.demo.stockmanage.mapper.StockManageMapper;
import org.jeecg.modules.demo.stockmanage.service.IStockManageService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description: 股东管理
 * @Author: jeecg-boot
 * @Date: 2022-01-14
 * @Version: V1.0
 */
@Service
public class StockManageServiceImpl extends ServiceImpl<StockManageMapper, StockManage> implements IStockManageService {
    @Resource
    private StockManageMapper stockManageMapper;

    // 查询股东列表
    @Override
    public IPage<StockManage> searchStockList(Page<StockManage> page, String stockName, String storeId) {
        return stockManageMapper.searchStockList(page, stockName, storeId);
    }

    // 查询股东统计数据
    @Override
    public StockDataCount getStockDataCount(String storeId, String stockId) {
        return stockManageMapper.getStockDataCount(storeId, stockId);
    }

    // 根据会员id查询股东信息
    @Override
    public StockManage getByMemberId(String memberId) {
        return stockManageMapper.getByMemberId(memberId);
    }

    // 查询股东分红统计
    @Override
    public StockDividendCount getStockDividendCount(String storeId, String stockId) {
        return stockManageMapper.getStockDividendCount(storeId, stockId);
    }

    // 查询股东股本统计
    @Override
    public StockEquityCount getStockEquityCount(String storeId, String memberId) {
        return stockManageMapper.getStockEquityCount(storeId, memberId);
    }

    // 设置股东管家
    @Override
    public void updateHouseKeeper(String id, String shareholdersHousekeeperId, String shareholdersRatio, String memberRatio) {
        stockManageMapper.updateHouseKeeper(id, shareholdersHousekeeperId, shareholdersRatio, memberRatio);
    }

    // 删除股东管家
    @Override
    public void deleteHouseKeeper(String shareholdersHousekeeperId) {
        stockManageMapper.deleteHouseKeeper(shareholdersHousekeeperId);
    }

    // 根据股东id删除股东管家
    @Override
    public void deleteHouseKeeperByStockId(String stockId) {
        stockManageMapper.deleteHouseKeeperByStockId(stockId);
    }

    // 减少可提现分红
    @Override
    public void updateCanWithdrawal(String stockId, Double totalDividend, Double withdrawalAmount) {
        stockManageMapper.updateCanWithdrawal(stockId, totalDividend, withdrawalAmount);
    }

    @Override
    public void refreshMemberQty() {
        stockManageMapper.refreshMemberQty();
    }

    public List<StockManage> getNoHousekeeperStockList(String storeId) {
        return stockManageMapper.getNoHousekeeperStockList(storeId);
    }

    @Override
    public void cleanShareholdersHousekeeper(String id) {
        stockManageMapper.cleanShareholdersHousekeeper(id);
    }

    @Override
    public IPage<Map<String, Object>> listStockDividendRecord(String storeId, String stockId, String createTime, Integer pageNo, Integer pageSize) {
        Page<Map<String, Object>> page = new Page<>(pageNo, pageSize);
        return stockManageMapper.listStockDividendRecord(page, storeId, stockId, createTime);
    }

    @Override
    public Double getStockDividendSum(String storeId, String memberId, String stockId) {
        return stockManageMapper.getStockDividendSum(storeId, memberId, stockId);
    }

    @Override
    public IPage<Map<String, Object>> listStockBalanceRecord(Page<Map<String, Object>> page, String storeId, String stockId, String createTime, String name) {
        return stockManageMapper.listStockBalanceRecord(page, storeId, stockId, createTime, name);
    }

    @Override
    public IPage<Map<String, Object>> listStockWidthRecord(String storeId, String stockId, String createTime, Integer pageNo, Integer pageSize) {
        Page<Map<String, Object>> page = new Page<>(pageNo, pageSize);
        return stockManageMapper.listStockWidthRecord(page, storeId, stockId, createTime);
    }

    public List<StockDividend> getListStockDividend(String stockId) {
        return stockManageMapper.getListStockDividend(stockId);
    }
}
